class Solution(object):
    def solveEquation(self, equation):
        """
        :type equation: str
        :rtype: str
        """
        x = 0
        v = 0
        s = equation.split('=')
        for state in range(2):
            t = s[state]
            n = len(t)
            left = 0
            right = 0
            last_op = '+'
            while right < n:
                if t[right] == 'x':
                    if right > left:
                        num = int(t[left: right])
                    else:
                        num = 1
                    if last_op == '+':
                        x += num * (1 - 2 * state)
                    else:
                        x -= num * (1 - 2 * state)
                    left = right + 1
                else:
                    if t[right] in {'+', '-'}:
                        if right > left:
                            num = int(t[left: right])
                            if last_op == '+':
                                v += num * (1 - 2 * state)
                            else:
                                v -= num * (1 - 2 * state)
                        last_op = t[right]
                        left = right + 1
                right += 1
            if right > left:
                num = int(t[left: right])
                if last_op == '+':
                    v += num * (1 - 2 * state)
                else:
                    v -= num * (1 - 2 * state)
        if not x:
            if v:
                return "No solution"
            else:
                return "Infinite solutions"
        if x:
            return "x=" + str(int(-v / x))







data = Solution()
equation = "x+5-3+x=6+x-2"
print(data.solveEquation(equation))
equation = "1=3"
print(data.solveEquation(equation))
equation = "2x=x"
print(data.solveEquation(equation))